package com.jdz.gxq.info.admin.export.action;

import java.io.BufferedReader;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.apache.log4j.Logger;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.jdz.gxq.info.admin.estate.bo.Estate;
import com.jdz.gxq.info.admin.export.bo.ExportEstateBo;

public class MobileFacadeAction extends Action {
	
	private Logger logger = Logger.getLogger(MobileFacadeAction.class);
 
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws java.lang.Exception {
		
		String method = request.getParameter("method");
		
		logger.info("MobileFacade Begin");
		
		System.out.println(method);
		
		String jsonReq = readJSONString(request);
		
		System.out.println(jsonReq);
		
		//Estate estate = estateService.getEstateById(editEstateForm.getId());
		
		Estate estate = new Estate();
		estate.setEnterpriseId(1001);
		estate.setEnterpriseName("企业名称");
		
		List<Estate> estateList = new ArrayList<Estate>();
		estateList.add(estate);
		estateList.add(estate);
		estateList.add(estate);
		
		ExportEstateBo exportEstateBo = new ExportEstateBo();
		exportEstateBo.setEstate(estate);
		exportEstateBo.setEstateList(estateList);
		exportEstateBo.setStatus("0");
		
		response.getWriter().print(JSONObject.fromObject(exportEstateBo).toString());
		
		logger.info("MobileFacade End");
		
		return null;
	}

	private String readJSONString(HttpServletRequest request) {
		
		StringBuffer json = new StringBuffer();
		try {
			
			/*	@SuppressWarnings("unchecked")
			Set<String> keySet = request.getParameterMap().keySet();
			
			if (keySet.size() == 1) {
				
				Iterator<String> i = keySet.iterator();
				while (i.hasNext()) {
					return i.next();
				}
			}*/
			
			String line = null;
			BufferedReader reader = request.getReader();
			while ((line = reader.readLine()) != null) {
				json.append(line);
			}
			
		} catch (Exception e) {
			logger.error("post request failed alarm.", e);
		}
		
		return json.toString();
	}
}

